import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text } from '@tarojs/components'
import { DNavBar, DModal } from '@/components'
import PropsType from 'prop-types'
import { AtModal, AtModalContent, AtModalAction, AtModalHeader, AtButton, AtIcon } from 'taro-ui'
import '../styles/dialog.scss'


export default class Ddialog extends Component {
  onCancel() {
      if (this.props.disabledCancel) return
    this.props.onCancel && this.props.onCancel()
  }

  onSure(e) {
    e.stopPropagation()
    this.props.onSure && this.props.onSure()
  }

  render() {
    const {
      isShow,
      title,
      btnText,
      content,
      disabledCancel
    } = this.props

    return (
      <AtModal isOpened={isShow} closeOnClickOverlay={!disabledCancel} onClose={this.onCancel.bind(this)}>
        <AtModalHeader className='title'>{title}
          <AtIcon value='close' size='15' className='close' onClick={this.onCancel.bind(this)}></AtIcon>
        </AtModalHeader>
        <AtModalContent className='con'>
          {content}
        </AtModalContent>
        <AtButton className='sure' onClick={this.onSure.bind(this)}>{btnText}</AtButton>
      </AtModal>
    )
  }
}
Ddialog.defaultProps = {
  isShow: false,
  title: '提示',
  content: '内容',
  btnText: '确定',
  double: true,
  onCancel: () => { },
  onSure: () => { },
  disabledCancel: false,
}
Ddialog.PropsType = {
  isShow: PropsType.bool,
  title: PropsType.string,
  content: PropsType.string,
  btnText: PropsType.string,
  double: PropsType.bool,
  onCancel: PropsType.func,
  onSure: PropsType.func
}
